home *** CD-ROM | disk | FTP | other *** search
- package com.simeda.ActiveViewer;
-
- import java.io.IOException;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
-
- public class VNCController implements Runnable {
- vncCanvas displayable = null;
- private String host = null;
- private String password = null;
- private int port = -1;
- public rfbProto rfb = null;
- public Display display = null;
- private Displayable next = null;
-
- public VNCController(Displayable var1) {
- this.next = var1;
- }
-
- public void setHost(String var1) {
- this.host = var1;
- }
-
- public void setPort(int var1) {
- this.port = var1;
- }
-
- public void setPassword(String var1) {
- this.password = var1;
- }
-
- public void setDisplay(Display var1) {
- this.display = var1;
- }
-
- public void doConnect() {
- try {
- this.displayable = new vncCanvas(this);
- this.display.setCurrent(this.displayable);
- this.connectAndAuthenticate();
- this.doProtocolInitialisation();
- Thread var1 = new Thread(this);
- var1.start();
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- }
-
- }
-
- public void run() {
- try {
- this.displayable.doInit(this.rfb);
- this.displayable.processNormalProtocol();
- } catch (Exception var2) {
- ((Throwable)var2).printStackTrace();
- }
-
- this.display.setCurrent(this.next);
- }
-
- public void connectAndAuthenticate() throws IOException {
- this.displayable.status("Connecting ...");
- this.rfb = new rfbProto(this.host, this.port);
- this.displayable.status("Reading supported version...");
- this.rfb.readVersionMsg();
- System.out.println("RFB server supports protocol version " + this.rfb.serverMajor + "." + this.rfb.serverMinor);
- this.displayable.status("ServerMajor: " + this.rfb.serverMajor + " ServerMinor:" + this.rfb.serverMinor);
- this.displayable.status("Writing own supported version ...");
- this.rfb.writeVersionMsg();
- this.displayable.status("Reading authentication scheme ...");
- switch (this.rfb.readAuthScheme()) {
- case 1:
- System.out.println("No authentication needed");
- this.displayable.status("No authentication needed");
- break;
- case 2:
- this.displayable.status("Password authentication");
- byte[] var1 = new byte[16];
- this.rfb.is.readFully(var1);
- String var2 = new String(this.password);
- if (var2.length() > 8) {
- var2 = var2.substring(0, 8);
- }
-
- byte[] var3 = new byte[8];
- byte[] var4 = var2.getBytes();
-
- for(int var5 = 0; var5 < var2.length(); ++var5) {
- var3[var5] = var4[var5];
- }
-
- for(int var6 = var2.length(); var6 < 8; ++var6) {
- var3[var6] = 0;
- }
-
- DesCipher var7 = new DesCipher(var3);
- var7.encrypt(var1, 0, var1, 0);
- var7.encrypt(var1, 8, var1, 8);
- this.rfb.os.write(var1);
- int var8 = this.rfb.is.readInt();
- switch (var8) {
- case 0:
- System.out.println("VNC authentication succeeded");
- break;
- case 1:
- System.out.println("VNC authentication failed");
- break;
- case 2:
- throw new IOException("VNC authentication failed - too many tries");
- default:
- throw new IOException("Unknown VNC authentication result " + var8);
- }
- }
-
- }
-
- void doProtocolInitialisation() throws IOException {
- System.out.println("sending client init");
- this.displayable.status("Writing client init...");
- this.rfb.writeClientInit();
- this.displayable.status("Reading server init ...");
- this.rfb.readServerInit();
- System.out.println("Desktop name is " + this.rfb.desktopName);
- System.out.println("Desktop size is " + this.rfb.framebufferWidth + " x " + this.rfb.framebufferHeight);
- this.displayable.status("Setting encodings...");
- this.setEncodings();
- }
-
- void setEncodings() {
- int[] var1 = new int[10];
- int var2 = 0;
- var1[var2++] = 5;
- var1[var2++] = 0;
- var1[var2++] = 2;
- var1[var2++] = 4;
-
- try {
- if (this.rfb != null && this.rfb.inNormalProtocol) {
- this.rfb.writeSetEncodings(var1, var2);
- }
- } catch (Exception var4) {
- ((Throwable)var4).printStackTrace();
- }
-
- }
- }
-